<?php 
include("common.php");
if(isset($_POST['submit'])){
	$username = $_POST['username'];
    $password = $_POST['password'];
	$nickname = $_POST['nickname'];
	
	$sql = "insert into user (username,password,nickname) values ('$username','$password','$nickname')";
	$result = mysql_query($sql);
	$rows=mysql_affected_rows();
	if($rows<1){
		echo "<script>alert('添加失败！');window.location.href='user.php';</script>";
	}else{
		echo "<script>alert('添加成功！');window.location.href='user.php';</script>";
	}

}

?>
<htnl>
<head>
<script type="text/javascript">
function checkForm(form) {
if(form.username.value == "") {
alert("用户名不能为空!");
form.username.focus();
return false;
}
if(form.password.value == "") {
alert("密码不能为空!");
form.password.focus();
return false;
}
if(form.nickname.value == "") {
alert("姓名不能为空!");
form.nickname.focus();
return false;
}
return true;
}
</script>
</head>
<body>
 <div class="fr righter">
		  <div class="title">
		  <h1 align="center"> 添加普通用户信息 </h1>
	      </div>
		  
		  <table class="bd" align="center" width="400">
		  <form action="#" method="post" onSubmit="return checkForm(this);">
		      <tr>
				  <td width="114" height="30" align="center">帐号：</td>
			    <td width="274" align="center"><input type="text" name="username" /></td>
			  </tr>
			  <tr>
				  <td align="center" height="30">密码：</td>
			    <td align="center"><input type="password" name="password" /></td>
			  </tr>
			  <tr>
				  <td align="center" height="30">姓名：</td>
			    <td align="center"><input type="text" name="nickname" /></td>
			  </tr>
			  
			  <tr>
				  <td height="30" colspan=2 align="center"><input type="submit" name="submit" value="添加"/> &nbsp;&nbsp;<input type="reset" name="submit" value="重置"/></td>
			  </tr>
		  </form>
	   </table>

	  </div>
  </div>
  
 </body>
</html>
 

